package binfa;

import java.sql.Connection;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class lock {

    public static void main(String[] args) {
        ReentrantLock reentrantLock=new ReentrantLock();
        Thread t=new Thread(()->{
            reentrantLock.lock();
           Condition condition= reentrantLock.newCondition();
            for(int i=0;i<5;i++){
                try {
                System.out.println(Thread.currentThread().getId()+" "+i);

                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            reentrantLock.unlock();
        });
        Thread t1=new Thread(()->{
            reentrantLock.lock();
            for(int i=0;i<5;i++){
                try {
                    System.out.println(Thread.currentThread().getId()+" "+i);

                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            reentrantLock.unlock();
        });
        t.start();
        t1.start();
    }
}
